package com.todoclipse.common;

/**
 * This exception is thrown when error during registration occurs
 * @author eximius
 *
 */
public class DaoException extends Exception {

	/**
	 * Uid
	 */
	private static final long serialVersionUID = 1510688364128072615L;
	
	/**
	 * Registration error type
	 * @author eximius
	 *
	 */
	public static enum ErrorType{
		ALREADY_REGISTRED, TOO_SHORT_PASSWORD,
		INVALID_EMAIL, INVALID_TIMEZONE, INVALID_FULL_NAME,
		LOGIN_ERROR, UNKNOWN_ERROR, ERROR_EMAIL_FOUND;
	}

	private final ErrorType errorType;
	
	/**
	 * Creates new exception with given ErrorType
	 * @param errorType
	 */
	public DaoException(ErrorType errorType) {
		this(errorType, null);
	}
	
	/**
	 * Creates new exception with giver ErrorType and message
	 * @param errorType
	 * @param message
	 */
	public DaoException(ErrorType errorType, String message) {
		super(message);
		this.errorType = errorType;
	}

	/**
	 * Invoke it if you want to know the cause of the problem
	 * @return registration ErrorType
	 */
	public ErrorType getErrorType() {
		return errorType;
	}

	@Override
	public String toString() {
		return "[Type: "+getErrorType()+"] "+super.toString();
	}
	
}
